<?php 
    class StudentInfo{
        var $student_id;
        var $name;
        var $gender;
        var $grade;
        var $major;
        var $class;
        var $phone;
    }
    class StudentInformationRegisterDAL{
        //获取学生的年级专业和班级
        public function getStudentGradeMajorClass($action,$instructor_id){

            $query_grade="select grade 
            from tb_student_info_list 
            where instructor_id=:instructor_id 
            and tb_student_info_list.status=1 
            group by `grade` 
            order by `grade`;";

            $query_major="select tb_major_list.major_id,tb_major_list.major_name 
            from tb_student_info_list,tb_major_list  
            where instructor_id=:instructor_id 
            and tb_student_info_list.status=1 
            and tb_major_list.major_id=tb_student_info_list.major_id 
            group by tb_major_list.major_id 
            order by tb_major_list.major_id;";

            $query_class="select class 
            from tb_student_info_list 
            where instructor_id=:instructor_id 
            and tb_student_info_list.status=1  
            group by `class` 
            order by `class`;";

            $pdo=myPDO::getInstance();
            switch($action){
                case 1:
                    $statement=$pdo->prepare($query_grade,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":instructor_id",$instructor_id);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 2:
                    $statement=$pdo->prepare($query_major,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":instructor_id",$instructor_id);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 3:
                    $statement=$pdo->prepare($query_class,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":instructor_id",$instructor_id);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                default:break;
            }
            
            return $result;
        }

        //获取辅导员的年级专业和班级
        public function getInstructorGradeMajorClass($action,$instructor_id){

            $query_grade="select grade from tb_instructor_info 
            where uid=:uid 
            and tb_instructor_info.status=1 
            order by `grade`;";

            $query_major="select tb_major_list.major_id,tb_major_list.major_name 
            from tb_instructor_info,tb_major_list  
            where uid=:uid 
            and tb_instructor_info.status=1 
            and tb_major_list.major_id=tb_instructor_info.major_id 
            order by tb_major_list.major_id";

            $query_class="select class 
            from tb_student_info_list 
            where instructor_id=:instructor_id 
            and tb_student_info_list.status=1  
            group by `class` 
            order by `class`;";

            $pdo=myPDO::getInstance();
            switch($action){
                case 1:
                    $statement=$pdo->prepare($query_grade,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructor_id);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 2:
                    $statement=$pdo->prepare($query_major,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":uid",$instructor_id);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 3:
                    $statement=$pdo->prepare($query_class,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":instructor_id",$instructor_id);
                    if($statement->execute()){
                        $result=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                default:break;
            }
            
            return $result;
        }

        public function getStudentGradeList(){

        }
        public function getStudentMajorList(){
            
        }
        public function getStudentClassList(){
            
        }

        //获取学生列表
        public function getStudentInformationList($action,$instructor_id,$grade,$major,$class,$page,$pageSize,$search=''){
            $result=null;
            $studentList=null;
            $query_found_rows='select FOUND_ROWS() as count;';
            //1-查询所有
            $query_all="select SQL_CALC_FOUND_ROWS student_id,name,grade,tb_major_list.major_id,tb_major_list.major_name,gender,class,phone_number from 
            tb_student_info_list,tb_major_list 
            where tb_student_info_list.instructor_id=:instructor_id 
            and tb_student_info_list.major_id=tb_major_list.major_id 
            and tb_student_info_list.status=1 
            order by student_id LIMIT :page,:pageSize;";
            //2
            $query_all_search="select SQL_CALC_FOUND_ROWS student_id,name,grade,tb_major_list.major_id,tb_major_list.major_name,gender,class,phone_number from 
            tb_student_info_list,tb_major_list 
            where tb_student_info_list.instructor_id=:instructor_id 
            and (tb_student_info_list.name=:search_name or tb_student_info_list.student_id=:search_id) 
            and tb_student_info_list.major_id=tb_major_list.major_id 
            and tb_student_info_list.status=1 
            order by student_id LIMIT :page,:pageSize;";

            //3-按年级查询
            $query_grade="select SQL_CALC_FOUND_ROWS student_id,name,grade,tb_major_list.major_id,tb_major_list.major_name,gender,class,phone_number from 
            tb_student_info_list,tb_major_list 
            where tb_student_info_list.instructor_id=:instructor_id 
            and tb_student_info_list.grade=:grade 
            and tb_student_info_list.major_id=tb_major_list.major_id 
            and tb_student_info_list.status=1 
            order by student_id LIMIT :page,:pageSize;";
            //4
            $query_grade_search="select SQL_CALC_FOUND_ROWS student_id,name,grade,tb_major_list.major_id,tb_major_list.major_name,gender,class,phone_number from 
            tb_student_info_list,tb_major_list 
            where tb_student_info_list.instructor_id=:instructor_id 
            and tb_student_info_list.grade=:grade 
            and tb_student_info_list.major_id=tb_major_list.major_id 
            and (tb_student_info_list.name=:search_name or tb_student_info_list.student_id=:search_id) 
            and tb_student_info_list.status=1 
            order by student_id LIMIT :page,:pageSize;";

            //5-按专业查询
            $query_major="select SQL_CALC_FOUND_ROWS student_id,name,grade,tb_major_list.major_id,tb_major_list.major_name,gender,class,phone_number from 
            tb_student_info_list,tb_major_list 
            where tb_student_info_list.instructor_id=:instructor_id 
            and tb_student_info_list.major_id=:major_id 
            and tb_student_info_list.major_id=tb_major_list.major_id 
            and tb_student_info_list.status=1 
            order by student_id LIMIT :page,:pageSize;";

            //6
            $query_major_search="select SQL_CALC_FOUND_ROWS student_id,name,grade,tb_major_list.major_id,tb_major_list.major_name,gender,class,phone_number from 
            tb_student_info_list,tb_major_list 
            where tb_student_info_list.instructor_id=:instructor_id 
            and tb_student_info_list.major_id=:major_id 
            and tb_student_info_list.major_id=tb_major_list.major_id 
            and (tb_student_info_list.name=:search_name or tb_student_info_list.student_id=:search_id) 
            and tb_student_info_list.status=1 
            order by student_id LIMIT :page,:pageSize;";

            //7-按年级、专业查询
            $query_grade_major="select SQL_CALC_FOUND_ROWS student_id,name,grade,tb_major_list.major_id,tb_major_list.major_name,gender,class,phone_number from 
            tb_student_info_list,tb_major_list 
            where tb_student_info_list.instructor_id=:instructor_id 
            and tb_student_info_list.grade=:grade 
            and tb_student_info_list.major_id=:major_id 
            and tb_student_info_list.major_id=tb_major_list.major_id 
            and tb_student_info_list.status=1 
            order by student_id LIMIT :page,:pageSize;";
            //8
            $query_grade_major_search="select SQL_CALC_FOUND_ROWS student_id,name,grade,tb_major_list.major_id,tb_major_list.major_name,gender,class,phone_number from 
            tb_student_info_list,tb_major_list 
            where tb_student_info_list.instructor_id=:instructor_id 
            and tb_student_info_list.grade=:grade 
            and tb_student_info_list.major_id=:major_id 
            and tb_student_info_list.major_id=tb_major_list.major_id 
            and (tb_student_info_list.name=:search_name or tb_student_info_list.student_id=:search_id) 
            and tb_student_info_list.status=1 
            order by student_id LIMIT :page,:pageSize;";

            //9-按年级、专业、班级查询
            $query_grade_major_class="select SQL_CALC_FOUND_ROWS student_id,name,grade,tb_major_list.major_id,tb_major_list.major_name,gender,class,phone_number from 
            tb_student_info_list,tb_major_list 
            where tb_student_info_list.instructor_id=:instructor_id 
            and tb_student_info_list.major_id=:major_id 
            and tb_student_info_list.grade=:grade 
            and tb_student_info_list.class=:class 
            and tb_student_info_list.major_id=tb_major_list.major_id 
            and tb_student_info_list.status=1 
            order by student_id LIMIT :page,:pageSize;";
            //10
            $query_grade_major_class_search="select SQL_CALC_FOUND_ROWS student_id,name,grade,tb_major_list.major_id,tb_major_list.major_name,gender,class,phone_number from 
            tb_student_info_list,tb_major_list 
            where tb_student_info_list.instructor_id=:instructor_id 
            and tb_student_info_list.major_id=:major_id 
            and tb_student_info_list.grade=:grade 
            and tb_student_info_list.class=:class 
            and tb_student_info_list.major_id=tb_major_list.major_id 
            and (tb_student_info_list.name=:search_name or tb_student_info_list.student_id=:search_id) 
            and tb_student_info_list.status=1 
            order by student_id LIMIT :page,:pageSize;";

            //11-
            $query_class="select SQL_CALC_FOUND_ROWS student_id,name,grade,tb_major_list.major_id,tb_major_list.major_name,gender,class,phone_number 
            from tb_student_info_list,tb_major_list 
            where tb_student_info_list.instructor_id=:instructor_id 
            and tb_student_info_list.major_id=tb_major_list.major_id 
            and tb_student_info_list.class=:class 
            and tb_student_info_list.status=1 
            order by student_id LIMIT :page,:pageSize;";

            //12
            $query_class_search="select SQL_CALC_FOUND_ROWS student_id,name,grade,tb_major_list.major_id,tb_major_list.major_name,gender,class,phone_number 
            from tb_student_info_list,tb_major_list 
            where tb_student_info_list.instructor_id=:instructor_id 
            and tb_student_info_list.major_id=tb_major_list.major_id 
            and tb_student_info_list.class=:class 
            and (tb_student_info_list.name=:search_name or tb_student_info_list.student_id=:search_id) 
            and tb_student_info_list.status=1 
            order by student_id LIMIT :page,:pageSize;";

            //13-
            $query_grade_class="select SQL_CALC_FOUND_ROWS student_id,name,grade,tb_major_list.major_id,tb_major_list.major_name,gender,class,phone_number 
            from tb_student_info_list,tb_major_list 
            where tb_student_info_list.instructor_id=:instructor_id 
            and tb_student_info_list.major_id=tb_major_list.major_id 
            and tb_student_info_list.grade=:grade 
            and tb_student_info_list.class=:class 
            and tb_student_info_list.status=1 
            order by student_id LIMIT :page,:pageSize;";

            //14-
            $query_grade_class_sreach="select SQL_CALC_FOUND_ROWS student_id,name,grade,tb_major_list.major_id,tb_major_list.major_name,gender,class,phone_number 
            from tb_student_info_list,tb_major_list 
            where tb_student_info_list.instructor_id=:instructor_id 
            and tb_student_info_list.major_id=tb_major_list.major_id 
            and tb_student_info_list.grade=:grade 
            and tb_student_info_list.class=:class 
            and (tb_student_info_list.name=:search_name or tb_student_info_list.student_id=:search_id) 
            and tb_student_info_list.status=1 
            order by student_id LIMIT :page,:pageSize;";

            //15-
            $query_major_class="select SQL_CALC_FOUND_ROWS student_id,name,grade,tb_major_list.major_id,tb_major_list.major_name,gender,class,phone_number 
            from tb_student_info_list,tb_major_list 
            where tb_student_info_list.instructor_id=:instructor_id 
            and tb_student_info_list.major_id=tb_major_list.major_id 
            and tb_student_info_list.major_id=:major_id 
            and tb_student_info_list.class=:class 
            and tb_student_info_list.status=1 
            order by student_id LIMIT :page,:pageSize;";

            //16-
            $query_major_class_sreach="select SQL_CALC_FOUND_ROWS student_id,name,grade,tb_major_list.major_id,tb_major_list.major_name,gender,class,phone_number 
            from tb_student_info_list,tb_major_list 
            where tb_student_info_list.instructor_id=:instructor_id 
            and tb_student_info_list.major_id=tb_major_list.major_id 
            and tb_student_info_list.major_id=:major_id 
            and tb_student_info_list.class=:class 
            and (tb_student_info_list.name=:search_name or tb_student_info_list.student_id=:search_id) 
            and tb_student_info_list.status=1 
            order by student_id LIMIT :page,:pageSize;";
            $pdo=myPDO::getInstance();

            switch($action){
                case 1:
                    $statement=$pdo->prepare($query_all,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":instructor_id",$instructor_id);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $studentList=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 2:
                    $statement=$pdo->prepare($query_all_search,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":instructor_id",$instructor_id);
                    $statement->bindValue(":search_name",$search);
                    $statement->bindValue(":search_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $studentList=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 3:
                    $statement=$pdo->prepare($query_grade,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":instructor_id",$instructor_id);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $studentList=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 4:
                    $statement=$pdo->prepare($query_grade_search,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":instructor_id",$instructor_id);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":search_name",$search);
                    $statement->bindValue(":search_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $studentList=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 5:
                    $statement=$pdo->prepare($query_major,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":instructor_id",$instructor_id);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $studentList=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 6:
                    $statement=$pdo->prepare($query_major_search,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":instructor_id",$instructor_id);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":search_name",$search);
                    $statement->bindValue(":search_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $studentList=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 7:
                    $statement=$pdo->prepare($query_grade_major,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":instructor_id",$instructor_id);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $studentList=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 8:
                    $statement=$pdo->prepare($query_grade_major_search,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":instructor_id",$instructor_id);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":search_name",$search);
                    $statement->bindValue(":search_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $studentList=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 9:
                    $statement=$pdo->prepare($query_grade_major_class,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":instructor_id",$instructor_id);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":class",$class);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $studentList=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 10:
                    $statement=$pdo->prepare($query_grade_major_class_search,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":instructor_id",$instructor_id);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":class",$class);
                    $statement->bindValue(":search_name",$search);
                    $statement->bindValue(":search_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $studentList=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 11:
                    $statement=$pdo->prepare($query_class,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":instructor_id",$instructor_id);
                    $statement->bindValue(":class",$class);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $studentList=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 12:
                    $statement=$pdo->prepare($query_class_search,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":instructor_id",$instructor_id);
                    $statement->bindValue(":class",$class);
                    $statement->bindValue(":search_name",$search);
                    $statement->bindValue(":search_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $studentList=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 13:
                    $statement=$pdo->prepare($query_grade_class,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":instructor_id",$instructor_id);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":class",$class);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $studentList=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 14:
                    $statement=$pdo->prepare($query_grade_class_search,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":instructor_id",$instructor_id);
                    $statement->bindValue(":grade",$grade);
                    $statement->bindValue(":class",$class);
                    $statement->bindValue(":search_name",$search);
                    $statement->bindValue(":search_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $studentList=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 15:
                    $statement=$pdo->prepare($query_major_class,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":instructor_id",$instructor_id);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":class",$class);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $studentList=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                case 16:
                    $statement=$pdo->prepare($query_major_class_search,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                    $statement->bindValue(":instructor_id",$instructor_id);
                    $statement->bindValue(":major_id",$major);
                    $statement->bindValue(":class",$class);
                    $statement->bindValue(":search_name",$search);
                    $statement->bindValue(":search_id",$search);
                    $statement->bindValue(":page",$page,PDO::PARAM_INT);
                    $statement->bindValue(":pageSize",$pageSize,PDO::PARAM_INT);
                    if($statement->execute()){
                        $studentList=$statement->fetchALL(PDO::FETCH_ASSOC);
                    }
                    $statement->closeCursor();
                    break;
                default:break;
            }
            if(!$studentList==null){
                $row=$pdo->query($query_found_rows);
                $count=$row->fetch(PDO::FETCH_ASSOC);
                $row->closeCursor();

                $result=array(
                    'studentList'=>$studentList,
                    'count'=>$count['count']
                );
            }

            return $result;
        }

        //添加学生信息
        public function addStudentInformation($instructor_id,$studentList){
            $query="insert into tb_student_info_list(instructor_id,student_id,name,gender,grade,major_id,class,phone_number,register_time,status) 
            values(:instructor_id,:student_id,:name,:gender,:grade,:major_id,:class,:phone_number,now(),1);";

            $pdo=myPDO::getInstance();
            try{
                $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
                $pdo->beginTransaction();
                
                $statement=$pdo->prepare($query,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                foreach($studentList as $student){
                    $statement->bindValue(":instructor_id",$instructor_id);
                    $statement->bindValue(":student_id",$student->student_id);
                    $statement->bindValue(":name",$student->name);
                    $statement->bindValue(":gender",$student->gender);
                    $statement->bindValue(":grade",$student->grade);
                    $statement->bindValue(":major_id",$student->major);
                    $statement->bindValue(":class",$student->class);
                    $statement->bindValue(":phone_number",$student->phone);
                    $result=$statement->execute();
                }
                
                $pdo->commit();
            }catch(Exception $e){
                $pdo->rollBack();
                //echo "Failed: ".$e->getMessage();
            }
            $statement->closeCursor();
            
            return $result;
        }

        //更新学生信息
        public function updateStudentInfomation($instructor_id,$studentList){
            $query="update tb_student_info_list set name=:name,gender=:gender,
            grade=:grade,major_id=:major_id,`class`=:class,phone_number=:phone_number 
            where instructor_id=:instructor_id and student_id=:student_id and status=1;";

            $pdo=myPDO::getInstance();
            try{
                $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
                $pdo->beginTransaction();

                $statement=$pdo->prepare($query,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                foreach($studentList as $student){
                    $statement->bindValue(":instructor_id",$instructor_id);
                    $statement->bindValue(":student_id",$student->student_id);
                    $statement->bindValue(":name",$student->name);
                    $statement->bindValue(":gender",$student->gender);
                    $statement->bindValue(":grade",$student->grade);
                    $statement->bindValue(":major_id",$student->major);
                    $statement->bindValue(":class",$student->class);
                    $statement->bindValue(":phone_number",$student->phone);
                    $result=$statement->execute();
                }
                
                $pdo->commit();
            }catch(Exception $e){
                $pdo->rollBack();
                //echo "Failed: ".$e->getMessage();
            }
            $statement->closeCursor();
            return $result;
        }

        //移除学生信息
        public function removeStudentInformation($instructor,$studentList){
            $query_remove_student="update tb_student_info_list set status=0 
            where instructor_id=instructor_id and student_id=:student_id;";
            $query_remove_dormitory="update tb_student_dormitory_roster set status=0 where student_id=:student_id;";
            $pdo=myPDO::getInstance();
            try{
                $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
                $pdo->beginTransaction();
                
                $statement=$pdo->prepare($query_remove_student,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                foreach($studentList as $student){
                    $statement->bindValue(":student_id",$student->student_id);
                    $result=$statement->execute();
                }

                $statement=$pdo->prepare($query_remove_dormitory,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
                foreach($studentList as $student){
                    $statement->bindValue(":student_id",$student->student_id);
                    $result=$statement->execute();
                }
                
                $pdo->commit();
            }catch(Exception $e){
                $pdo->rollBack();
                //echo "Failed: ".$e->getMessage();
            }
            $statement->closeCursor();
            return $result;
        }

        //获取辅导员年级与专业列表
        public function getInstructorGradeAndMajorList($instructor){
            $result=null;
            $query="select tb_major_list.major_id,tb_major_list.major_name,grade from tb_instructor_info,tb_major_list 
            where uid=:uid and tb_instructor_info.major_id=tb_major_list.major_id and tb_instructor_info.status=1;";
            
            $pdo=$pdo=myPDO::getInstance();
            $statement=$pdo->prepare($query,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
            $statement->bindValue(":uid",$instructor);
            if($statement->execute()){
                $result=$statement->fetchALL(PDO::FETCH_ASSOC);
            }
            $statement->closeCursor();
            return $result;
        }

        //查询学生是否已存在
        public function isStudent($student_id){
            $query="select count(1) as count from tb_student_info_list where student_id=:student_id;";
            
            $pdo=$pdo=myPDO::getInstance();
            $statement=$pdo->prepare($query,array(PDO::ATTR_CURSOR =>PDO::CURSOR_FWDONLY));
            $statement->bindValue(":student_id",$student_id);
            if($statement->execute()){
                $result=$statement->fetch(PDO::FETCH_ASSOC);
            }
            $statement->closeCursor();
            return $result;
        }
        
    }
?>